// DrRange
package main

import (
	"fmt"
	"strconv"
)

type DrRange struct {
	DrAbstractObject
	IIterable
	value int
	start int
	end   int
	step  int
}

func NewRange(start, end, step int) *DrRange {
	result := new(DrRange)
	result.start = start
	result.end = end
	result.step = step
	result.Type = TypeRange
	return result
}

func (self *DrRange) ResetCursor() {
	self.value = self.start
}
func (self *DrRange) Next() IObject {
	current := self.value

	if self.step > 0 && self.value >= self.end {
		return nil
	}
	if self.step < 0 && self.value <= self.end {
		return nil
	}
	self.value += self.step
	return NewInt(current)
}
func (self *DrRange) AsString() string {
	return "<range(" + strconv.FormatInt(int64(self.start), 10) + "," + strconv.FormatInt(int64(self.end), 10) + "," + strconv.FormatInt(int64(self.step), 10) + ")>"
}
func (self *DrRange) getType() DataType {
	return self.Type
}
func (self *DrRange) Print(interp *Interpreter) {
	fmt.Print(self.AsString())
}
